package com.csun.cmny.provider.controller.rpc;

import com.csun.cmny.provider.model.dto.sleep.BedOldmanSleepReqDto;
import com.csun.cmny.provider.model.vo.SleepCareDataReqVo;
import com.csun.cmny.provider.service.DmcSleepCareDataFeignApi;
import com.csun.cmny.provider.service.DmcSleepCareDataService;
import com.csun.cmny.provider.task.AppSleepDataQuartz;
import com.csun.cmny.provider.task.RefreshExpireKeyQuartz;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-03-14 21:09
 * @Description: the class dmc sleep care data feign client
 */
@Slf4j
@RestController
public class DmcSleepCareDataFeignClient implements DmcSleepCareDataFeignApi {

    @Resource
    private DmcSleepCareDataService dmcSleepCareDataService;
    @Resource
    private AppSleepDataQuartz appSleepDataQuartz;
    @Resource
    private RefreshExpireKeyQuartz refreshExpireKeyQuartz;

    @Override
    public Wrapper<List<SleepCareDataReqVo>> querySleepCareDataByBedOldmanList(@RequestBody List<BedOldmanSleepReqDto> bedOldmanSleepReqDtoList) {

        List<SleepCareDataReqVo> sleepCareDataReqVoList = dmcSleepCareDataService.querySleepCareDataByBedOldmanList(bedOldmanSleepReqDtoList);

        return WrapMapper.ok(sleepCareDataReqVoList);
    }

    @Override
    public Wrapper calcSleepDate() {

        log.info(">>>>>>>>>>>>>>>开始生成睡眠数据<<<<<<<<<<<<<<<<<");
        appSleepDataQuartz.calc();
        log.info(">>>>>>>>>>>>>>>睡眠数据计算完成<<<<<<<<<<<<<<<<<");

        return WrapMapper.ok();
    }

    @Override
    public Wrapper refreshRedisKey(@RequestParam("time") String time) {

        // log.info(">>>>>>>>>>>>>>>refresh redis key<<<<<<<<<<<<<<<<<");
        //refreshExpireKeyQuartz.refresh();

        // 执行夜间巡视报警任务
        String str = time.substring(11, 19);
        //refreshExpireKeyQuartz.checkOldmanInRoomAtNight(str);

        // 执行设备升级指令
        //refreshExpireKeyQuartz.deviceUpdateCheck(time);

        return WrapMapper.ok();
    }
}
